﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Serialization;

namespace NetLib
{
    [Serializable]
    [XmlInclude(typeof(NamedNode))]
    [XmlInclude(typeof(UnnamedNode))]
    public class Node
    {

        public int id
        {
            get;
            set;
        }

        public bool Marked
        {
            get;
            set;
        }
        public Node()
        {
            Marked = false;
        }
    }
    [Serializable]
    public class UnnamedNode : Node
    {
        /// <summary>
        /// true если measure
        /// </summary>
        public bool type
        {
            get;
            set;
        }
        public UnnamedNode()
        {

        }
        public UnnamedNode(int _id, bool _marked, bool _type)
        {
            type = _type;
            id = _id;
            Marked = _marked;
        }
    }
    [Serializable]
    public class NamedNode : Node
    {


        public string name
        {
            get;
            set;
        }

        public NamedNode()
        {           

        }
        public NamedNode(int _id,bool _marked,string _name)
        {
            name = _name;
            id = _id;
            Marked = _marked;
        }
    }

    [Serializable]
    public class Link
    {
        //a_part_of,a_set_of,is_a, object, value, measure
        public string type
        {
            get;
            set;
        }

        public Node start_node
        {
            get;
            set;
        }

        public Node end_node
        {
            get;
            set;
        }
        public Link()
        {
        }
        public Link(Node _start,Node _end, string _type)
        {
            start_node = _start;
            end_node = _end;
            type = _type;
        }
    }

    [Serializable]
    public class synset
    {
        public string mainname{get; set; }
        public List<string> synlist { get; set; }
        public synset()
        {
            
        }
        public synset(string _mianname,List<string> _synlist)
        {
            mainname = _mianname;
            synlist = _synlist;
        }
       

    }
    [Serializable]
    public class Net
    {
        public List<Node> nodes
        {
            get;
            set;
        }

        public List<Link> links
        {
            get;
            set;
        }

        public List<synset> synsets { get; set; }
        public Net()
        {
            nodes = new List<Node>();
            links = new List<Link>();
            synsets=new List<synset>();
        }
        public Node GetNode(int id)
        {
             return (from c in nodes where c.id==id select c).First();
        }
        public void Serialize(string path)
        {
            if(File.Exists(path))
            {
               File.Delete(path);
            }
            XmlSerializer XmlSer = new XmlSerializer(typeof(Net));
            FileStream stream = new FileStream(path, FileMode.OpenOrCreate);      
            XmlSer.Serialize(stream,this);
            stream.Close();
        }

        private FileInfo FileInfo()
        {
            throw new NotImplementedException();
        }
         public List<string> GetSynonyms(string name)
         {
             return (from s in synsets where s.mainname == name select s.synlist).First();
         }
      
    }
}
